/**
 * Copyright 2009 University of  Washington
 * This code is released under the GPL version 3 - with a copy of the license included
 * @author Maya Hao Li
 *
 */
package seedpod.webapp.view.htmlwidget;

public class TextAreaInput extends GenericHtmlWidget
{

  public static final int DEFAULT_HEIGHT = 2;
  public static final int DEFAULT_WIDTH = 50;

  private String _value;
  private int _height, _width;

  public TextAreaInput ( String widgetID )
  {
    super( widgetID );
    _value = "";
    _height = DEFAULT_HEIGHT;
    _width = DEFAULT_WIDTH;
  }

  public TextAreaInput ( String widgetID, String value )
  {
    super( widgetID );
    _value = value;
    _height = DEFAULT_HEIGHT;
    _width = DEFAULT_WIDTH;
  }

  public void setSize ( int width, int height )
  {
    _width = width;
    _height = height;
  }

  public String render()
  {
    String html = "<textarea ";
    html += ATT( "class", _cssClass );
    html += ATT( "id", _widgetID );
    html += ATT( "name", _widgetID);
    html += ATT( "rows", _height );
    html += ATT( "cols", _width );
    html += ">";
    html += _value;
    html += "</textarea>";

    // javascript for textarea resize
    html += "<img src=\"image/resize.gif\" onMouseDown=\"startExpandTextarea(event, "+_widgetID+");\" ";
    html += "onSelect=\"return false;\" ondragstart=\"return false;\" alt=\"Expand button\" ";
    html += "title=\"Expand this text box\" onMouseOver=\"this.style.cursor='se-resize';\"/>";

    return html;
  }


}